package com.example.demotdd.user;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wangbin
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    UserRepository userRepository;

    @GetMapping
    public List<User> userList() {
        return userRepository.findAll();
    }

    @GetMapping("/{id}")
    public User userDetail(@PathVariable String id) {
        return userRepository.findById(id).orElseThrow();
    }

    @PostMapping
    public void saveUser(@RequestBody User user) {
        userRepository.save(user);
    }
}
